package com.bianyuanren.v4.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.Data;

/**
 * @author 微笑的你
 * @version 1.0
 * @date 2020/1/2 9:35
 */
public class JsonUtils {
    private final static Gson GSON = new GsonBuilder().create();

    public static String toJson(Object obj){
        return GSON.toJson(obj);
    }

    public static <T> T fromJson(String json,Class<T> clazz){
        return GSON.fromJson(json, clazz);
    }

    public static void main(String[] args) {
        Mm mm = new Mm();
        mm.setG("1");
        mm.setM("1");
        mm.setI("1");
        String s = toJson(mm);
        System.out.println(s);
        Mm mm1 = fromJson(s, Mm.class);
        System.out.println("mm1 = " + mm1);
    }
}
@Data
class Mm{
    private String i;
    private String m;
    private String g;
}


